class Solution4 {

    int ret, aim;

    public int findTargetSumWays(int[] nums, int target) {
        aim = target;

        dfs(nums, 0, 0);
        return ret;
    }

    public void dfs(int[] nums, int pos, int path){
        if(pos == nums.length){
            if(path == aim) { ret++;}
            return ;
        }

        dfs(nums, pos + 1, path + nums[pos]);

        dfs(nums, pos + 1, path - nums[pos]);
    }
}